package com.zhaoyu.admin.job;

import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

@Log4j2
@Configuration
@PropertySource("classpath:xxljob.properties") // 指定扫描配置文件
public class XxlJobConfig {

    @Value("${xxljob.admin.addresses}")
    private String addresses;

    @Value("${xxljob.executor.appname}")
    private String appName;

    @Value("${xxljob.executor.port}")
    private int port;

    @Bean
    public XxlJobSpringExecutor xxlJobExecutor() {
        log.info(">>>>>>>>>>> xxl-job config init.");
        XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor(); // 创建 XXL-Job 全局配置,XXL-Job 启动时会自动创建
        xxlJobSpringExecutor.setAdminAddresses(addresses); // 地址
        xxlJobSpringExecutor.setAppName(appName); // 应用名称
        xxlJobSpringExecutor.setPort(port); // 端口
        xxlJobSpringExecutor.setLogRetentionDays(30); // 日志保存时长,默认为30天
        return xxlJobSpringExecutor;
    }

}